//
//  VWTsModel.swift
//  VideoWatcher
//
//  Created by JY_NEW on 2021/10/27.
//  Copyright © 2021 JunYue. All rights reserved.
//

import Foundation
import CommonCrypto

/// tsModel
public struct M3u8TsModel: MultiFileModelType {
    /// ts时长
    public let duration: Float
    /// 本地路径
    public let url: String
    /// 文件名
    public let filename: String
    
    public init(duration: Float, url: String) {
        self.duration = duration
        self.url = url
        self.filename = Self.md5(for: url)
    }
    private static func md5(for string: String) -> String {
        let utf8 = string.cString(using: .utf8)
        var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
        CC_MD5(utf8, CC_LONG(utf8!.count - 1), &digest)
        return digest.reduce("") { $0 + String(format:"%02X", $1) }
    }

}
